package com.msh.starter.qrcode.config;

import com.msh.frame.client.interfaces.IClassLoadLog;
import com.msh.frame.interfaces.IQrCode;
import com.msh.starter.qrcode.instance.QrCodeGenerator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import(QrCodeProperties.class)
public class QrCodeAutoConfiguration implements IClassLoadLog {

  @Bean
  @ConditionalOnProperty(name = "msh.starter.qrcode.enable", havingValue = "true", matchIfMissing = true)
  public IQrCode qrCodeGenerator(QrCodeProperties qrCodeProperties){
    return new QrCodeGenerator(qrCodeProperties);
  }

  @Override
  public String logInfo() {
    StringBuilder sb = new StringBuilder().append("----执行类 ")
            .append(QrCodeAutoConfiguration.class)
            .append("\r\n")
            .append("--------加载类 ")
            .append(QrCodeGenerator.class)
            .append("(IQrCode)\r\n");
    return sb.toString();
  }
}
